package com.sina.shop.timer.config;

import com.sina.shop.dao.config.DaoConfig;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.io.ResourceLoader;
import org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * 段浩杰   2018-01-08-17:16
 */
@Configuration
@Import(DaoConfig.class)
public class TimerContextConfig implements ResourceLoaderAware {

    private ResourceLoader resourceLoader;

    @Override
    public void setResourceLoader(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;

    }

    /**
     * 创建一个任务被持久化的调度器,推荐使用此调度器的前提是 任务不太多,若任务太多,请使另建调度器,因为一个表的记录太多会影响调度性能
     */
    @Bean
    public SchedulerFactoryBean commonPersistScheduler() {
        SchedulerFactoryBean factoryBean = new SchedulerFactoryBean();
        factoryBean.setConfigLocation(resourceLoader.getResource("classpath:scheduler/common-scheduler.properties"));
        return factoryBean;
    }

    //public MethodInvokingJobDetailFactoryBean

   // public SchedulerFactoryBean

}